<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 100px;
            height: 100px;
            background: red;
        }
    </style>
</head>
<body>
    <div class="box" id="box">

    </div>
</body>
<script>
    var box = document.getElementById("box");
    box.onmousedown = function(e){
        var x=e.offsetX;
        var y=e.offsetY;
        console.log(x,y);
        document.onmousemove=function(event){
            console.log(event.clientX);
            console.log(event.clientY);
            var clientX = event.clientX;
            var clientY = event.clientY;
            box.style.left = (clientX - x) +"px";
            box.style.top = (clientY - y) +"px";
        }
    }
    // box.onmouseout = function(){
    //     document.onmousemove = null;
    // }
</script>
</html>